package com.fedming.bottomnavigationdemo.Adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fedming.bottomnavigationdemo.R;

import java.util.List;

public class ConditionAdapter extends RecyclerView.Adapter<ConditionAdapter.ViewHolder> {
    private List<String> mList;//数据源

    public ConditionAdapter(List<String> list) {
        mList = list;
    }

    @Override
    public ConditionAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.condition, parent, false);
        final ConditionAdapter.ViewHolder holder = new ConditionAdapter.ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(ConditionAdapter.ViewHolder holder, int position) {
        String condition =  mList.get(position);
        holder.condition.setText(condition);
    }

    public void removeData(int position) {
        mList.remove(position);
        notifyItemRemoved(position);
    }
    public void addData(int position,String condition) {
        mList.add(position, condition);
        notifyItemInserted(position);
    }

    //更改某个位置的数据
    public void changeData(int position,String condition) {
        mList.set(position, condition);
        notifyItemChanged(position);
    }


    @Override
    public int getItemCount() {
        return mList.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView condition;
        public ViewHolder(View view) {
            super(view);
            condition = view.findViewById(R.id.condition);
        }

    }

}
